#include <iostream>
using namespace std;


int main(){
	int n,k,ans=0;
	cin>>n>>k;
	char a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i != 0  &&  ((a[i] == 'L'  &&  a[i-1] == 'L')  ||  (a[i] == 'R'  &&  a[i-1] == 'R')))
			ans++;
	}
	int s=0,t=n-1;
	while(s < t  &&  k > 0){
		if(a[s] == a[s+1]){
			s++;
			continue;
		}
		if(a[t] == a[t-1]){
			t--;
			continue;
		}
		if(a[s] != a[t]){
			s++;
			t--;
			continue;
		}
		ans += 2;
		s++;
		t--;
		k--;
	}
	cout<<ans;
	return 0;
}
